package com.chanct.test;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class test3 {

	public static void main(String[] args) {
		Timestamp ts = new Timestamp(System.currentTimeMillis());   
		String tsStr = "2011-05-09 11:49:45";   
		try {   
		    ts = Timestamp.valueOf(tsStr);   
		    System.out.println(ts);   
		 } catch (Exception e) {   
		    e.printStackTrace();   
		 }
		System.out.println(System.currentTimeMillis());
		
		try {
			System.out.println(howManyDays("1992-05-22"));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		System.out.println(changInt(4));
	}
	public static int howManyDays(String s) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		long date1 = sdf.parse(s).getTime();
		Date date = new Date();
		long date2 = date.getTime();
		long time = date2-date1;
		int day = (int)(time/(3600*24*1000));
		return day;
	}
	
	public static String changInt(int s){
		String temp = String.valueOf(s);
		for(int i=4-temp.length();i>0;i--){
			temp = "0" + temp;
		}
		return temp;		
	}
	
	
}
